//
//  OriginalTableViewCell.m
//  littleLight's Project-A
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 light. All rights reserved.
//

#import "OriginalTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface OriginalTableViewCell ()
@property (nonatomic, strong) UIView *view;
@end
@implementation OriginalTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
        
    }

    return self;
    
}
- (void)createView
{
    self.cover_image_default = [[UIImageView alloc] init];
    self.cover_image_default.layer.masksToBounds = YES;
    self.cover_image_default.layer.cornerRadius = 5;
    self.cover_image_default.alpha = 1;
    [self.contentView addSubview:self.cover_image_default];
   
    _view = [[UIView alloc] init];
    [self.contentView addSubview:_view];
    _view.backgroundColor = [UIColor blackColor];
    _view.alpha = 0.2;
    _view.layer.masksToBounds = YES;
    _view.layer.cornerRadius = 5;
    self.name = [[UILabel alloc] init];
    self.name.font = [UIFont systemFontOfSize:23];
    self.name.numberOfLines = 0;
    self.name.textColor = [UIColor whiteColor];
    self.name.font = [UIFont boldSystemFontOfSize:20];
    [self.contentView addSubview:self.name];
    
    self.lanImageV = [[UIImageView alloc] init];
    self.lanImageV.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.lanImageV];
    
    self.first_day = [[UILabel alloc] init];
    self.first_day.font = [UIFont systemFontOfSize:12];
    self.first_day.textColor = [UIColor whiteColor];
    self.first_day.font = [UIFont boldSystemFontOfSize:12];
    [self.contentView addSubview:self.first_day];
    
    self.day_count = [[UILabel alloc] init];
    self.day_count.font = [UIFont systemFontOfSize:12];
    self.day_count.textColor = [UIColor whiteColor];
    self.day_count.font = [UIFont boldSystemFontOfSize:12];
    [self.contentView addSubview:self.day_count];
    
    self.view_count = [[UILabel alloc] init];
    self.view_count.font = [UIFont systemFontOfSize:12];
    self.view_count.textColor = [UIColor whiteColor];
    self.view_count.font = [UIFont boldSystemFontOfSize:12];
    [self.contentView addSubview:self.view_count];
    
    self.popular_place_str = [[UILabel alloc] init];
    self.popular_place_str.font = [UIFont systemFontOfSize:12];;
    self.popular_place_str.textColor = [UIColor whiteColor];
    self.popular_place_str.font = [UIFont boldSystemFontOfSize:12];
    [self.contentView addSubview:self.popular_place_str];
    
    self.userName = [[UILabel alloc] init];
    self.userName.font = [UIFont boldSystemFontOfSize:12];
    [self.contentView addSubview:self.userName];
    self.userName.textColor = [UIColor whiteColor];
    self.avatar_s = [[UIImageView alloc] init];
    self.avatar_s.layer.masksToBounds = YES;
    self.avatar_s.layer.cornerRadius = 15;
    [self.contentView addSubview:self.avatar_s];
    
    
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.cover_image_default.frame = CGRectMake(10, 5, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 10);
    self.name.frame = CGRectMake(15, 10, self.frame.size.width - 20, 0);
    [self.name sizeToFit];
    
    self.view.frame = self.cover_image_default.frame;
    
    self.lanImageV.frame = CGRectMake(self.name.frame.origin.x, self.name.frame.size.height + 5 + 10, 5, 40);
    self.first_day.frame = CGRectMake(self.name.frame.origin.x + 10,  self.name.frame.size.height + 5 + 5, 80, 30);
    self.day_count.frame = CGRectMake(self.name.frame.origin.x + 10 + 80,  self.name.frame.size.height + 5 + 5, 40, 30);
    self.view_count.frame = CGRectMake(self.name.frame.origin.x + 10 + 80 + 40, self.name.frame.size.height + 5 + 8, 100, 25);
    self.popular_place_str.frame = CGRectMake(self.name.frame.origin.x + 10, self.name.frame.size.height + 5 + 5 + 25, 200, 25);
    
    
    self.avatar_s.frame = CGRectMake(self.name.frame.origin.x, self.cover_image_default.frame.size.height - 40, 30 , 30);
    self.userName.frame = CGRectMake(self.name.frame.origin.x + 10 + 30, self.cover_image_default.frame.size.height - 50, 200, 50);
    
    
    
    
}

- (void)setModel:(ElementsData *)model
{
    _model = model;
    [self.cover_image_default sd_setImageWithURL:[NSURL URLWithString:_model.cover_image_w640]];
    self.name.text = _model.name;
    self.lanImageV.image = [UIImage imageNamed:@"OriginalCellPic1"];
    self.first_day.text = _model.first_day;
    self.day_count.text = [NSString stringWithFormat:@"%@天",[_model.day_count stringValue]];
    self.view_count.text = [NSString stringWithFormat:@"%@次浏览",[_model.view_count stringValue]];
    self.popular_place_str.text = _model.popular_place_str;
    [self.avatar_s sd_setImageWithURL:[NSURL URLWithString:_model.userModel.avatar_s]];
    self.userName.text = [NSString stringWithFormat:@"by %@",_model.userModel.name];
    

}











@end
